www.gusucode.com > VC 圆形时钟程序(实现指针移动与修改时间)-源码程序 > VC 圆形时钟程序(实现指针移动与修改时间)-源码程序/code/Test13_4View.cpp
//Download by http://www.NewXing.com // Test13_4View.cpp : implementation of the CTest13_4View class // #include "stdafx.h" #include "Test13_4.h" #include "changeTime.h" #include "Test13_4Doc.h" #include "Test13_4View.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CTest13_4View IMPLEMENT_DYNCREATE(CTest13_4View, CView) BEGIN_MESSAGE_MAP(CTest13_4View, CView) //{{AFX_MSG_MAP(CTest13_4View) ON_WM_TIMER() ON_WM_LBUTTONDOWN() ON_WM_LBUTTONDBLCLK() //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CTest13_4View construction/destruction CTest13_4View::CTest13_4View() { // TODO: add construction code here //SetTimer(0, 1000, NULL); } CTest13_4View::~CTest13_4View() { } BOOL CTest13_4View::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CTest13_4View drawing void CTest13_4View::OnDraw(CDC* pDC) { CTest13_4Doc* pDoc = GetDocument(); ASSERT_VALID(pDoc); SetTimer(0, 1000, NULL); CPen *oldPen, *cPen; CBrush *oldBrush, *cBrush; //画出大的圆 cPen = new CPen(PS_SOLID, 3, RGB(255,132,123)); cBrush = new CBrush(RGB(123,132,123)); oldPen = pDC->SelectObject(cPen); oldBrush = pDC->SelectObject(cBrush); pDC->Ellipse(pDoc->m_Rect); pDC->SelectObject(oldPen); pDC->SelectObject(oldBrush); //画出中心的一个圆 cBrush = new CBrush(RGB(255,132,123)); pDC->SelectObject(cBrush); pDC->Ellipse(pDoc->m_centerRect); pDC->SelectObject(oldBrush); //得到矩形的另个点,画出四个分线 cPen = new CPen(PS_SOLID, 2, RGB(255,222,123)); oldPen = pDC->SelectObject(cPen); CPoint tl = pDoc->m_Rect.TopLeft(); CPoint br = pDoc->m_Rect.BottomRight(); pDC->MoveTo((br.x+tl.x)/2, tl.y); pDC->LineTo((br.x+tl.x)/2, tl.y+20); pDC->MoveTo((br.x+tl.x)/2, br.y); pDC->LineTo((br.x+tl.x)/2, br.y-20); pDC->MoveTo(tl.x, (br.y+tl.y)/2); pDC->LineTo(tl.x+20, (br.y+tl.y)/2); pDC->MoveTo(br.x, (br.y+tl.y)/2); pDC->LineTo(br.x-20, (br.y+tl.y)/2); pDC->SelectObject(oldPen); //画出刻度 pDC->MoveTo(326,122); pDC->LineTo(320,134); pDC->MoveTo(377,175); pDC->LineTo(365,183); //// pDC->MoveTo(377,323); pDC->LineTo(365,317); pDC->MoveTo(326,378); pDC->LineTo(320,365); //// pDC->MoveTo(175,377); pDC->LineTo(183,365); pDC->MoveTo(122,326); pDC->LineTo(134,320); //// pDC->MoveTo(122,177); pDC->LineTo(134,183); pDC->MoveTo(177,122); pDC->LineTo(183,134); //画出三个时针、分针、秒针 //hour pDC->MoveTo(pDoc->m_org); pDC->LineTo(pDoc->m_hourEndPoint); //minutin pDC->MoveTo(pDoc->m_org); pDC->LineTo(pDoc->m_minEndPoint); //second pDC->MoveTo(pDoc->m_org); pDC->LineTo(pDoc->m_secEndPoint); // TODO: add draw code for native data here } ///////////////////////////////////////////////////////////////////////////// // CTest13_4View printing BOOL CTest13_4View::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CTest13_4View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CTest13_4View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } ///////////////////////////////////////////////////////////////////////////// // CTest13_4View diagnostics #ifdef _DEBUG void CTest13_4View::AssertValid() const { CView::AssertValid(); } void CTest13_4View::Dump(CDumpContext& dc) const { CView::Dump(dc); } CTest13_4Doc* CTest13_4View::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTest13_4Doc))); return (CTest13_4Doc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CTest13_4View message handlers void CTest13_4View::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default CTest13_4Doc* pDoc = GetDocument(); ASSERT_VALID(pDoc); pDoc->m_TickAdd(); pDoc->M_MoveClockHands(); this->InvalidateRect(CRect(130,130,370,370)); CView::OnTimer(nIDEvent); } void CTest13_4View::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default // CString s; // s.Format("%d, %d",point.x , point.y); // MessageBox(s); CView::OnLButtonDown(nFlags, point); } void CTest13_4View::OnLButtonDblClk(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CTest13_4Doc* pDoc = GetDocument(); ASSERT_VALID(pDoc); changeTime ctime; if(ctime.DoModal() == IDOK) { pDoc->m_hour = ctime.m_Hour; pDoc->m_min = ctime.m_Min; pDoc->m_sec = ctime.m_Sec; //改变系统时间 if(ctime.m_ChangeSysTime) { CTime time = CTime::GetCurrentTime(); SYSTEMTIME tm; tm.wYear = time.GetYear(); tm.wDay = time.GetDay(); tm.wMonth = time.GetMonth(); tm.wHour = ctime.m_Hour; tm.wMinute = ctime.m_Min; tm.wSecond = ctime.m_Sec; tm.wMilliseconds = 0; SetLocalTime(&tm); } pDoc->M_MoveClockHands(); } CView::OnLButtonDblClk(nFlags, point); }